﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Projekt
{
    public partial class editProduce1 : Form
    {
        private DataTable produceTable;
        public editProduce1()
        {
            InitializeComponent();
        }

        private void produceList_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        private void editProduce_Load(object sender, EventArgs e)
        {
            try
            {
                Produce termek = new Produce();
                produceTable = termek.getProduceList();
                foreach (DataRow rows in produceTable.Rows)
                {
                    ListViewItem lt = new ListViewItem(rows["ANev"].ToString());
                    lt.SubItems.Add(rows["AMeret"].ToString());
                    produceList.Items.Add(lt);
                }
            }
            catch (Exception es) { MessageBox.Show(es.ToString()); }

        }

        private void deleteMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                Produce termek = new Produce();
                ListViewItem item = produceList.FocusedItem;
                String Message = "Do you wan to delete " + item.SubItems[0].Text;
                DialogResult result = MessageBox.Show(Message, "Delete", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    if (termek.DeleteProduce(item.SubItems[0].Text)) produceList.Items.Remove(item);
                    else MessageBox.Show("This produce can't be deleted. Probably this produce is in use by other tables");
                }
            }
            catch (Exception es) { MessageBox.Show(es.ToString()); };
        }

 
    }
}
